<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<?php
 // definimos variables
 $online=0;
 $offline=0;
?>

    <head>
        <meta charset="utf-8">
        <!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><![endif]-->
        <title>RasPi</title>
    	<meta name="keywords" content="raspeberry pi, pi, raspi, haelsite, bash, sql, mysq, linux, web" />
		<meta name="description" content="raspeberry pi, pi, raspi, haelsite, bash, sql, mysq, linux, web" />
        <meta name="viewport" content="width=device-width">
		<!-- Google Web Font Embed -->
        <link href='http://fonts.googleapis.com/css?family=Raleway:400,600,500,300,700' rel='stylesheet' type='text/css'>
        <link rel="stylesheet" href="css/estilos.css">   
    </head>
    <body>
		
        <div id="main-wrapper">
            <!--[if lt IE 7]>
                <p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
            <![endif]-->

            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 affix text-center" style="z-index: 1;">
                <h1 class="templatemo-site-title">
                        RasPi Server                        
                </h1>
				
				<div class="text-warning"> </div>

				<button type="button" class="btn btn-default btn-lg">
				  <span class="glyphicon glyphicon-star"></span><a href="index_calendar.php"  target="_blank">Ir a Calendario</a>
				</button>
				<p>This calendar shows the speed of my internet connection provided by ONO and continually falls suffers unjustified. This website attempts to present the truths and lies of the flat rate ONO.</p>

					
                <ul id="responsive" style="display:none" class="hidden-lg hidden-md"></ul><!-- /.responsive -->
            </div>
			<!--img src='classes/pChart.php' /-->
			<img src="images/testvelocidad.jpg" height="100%" width="100%" />
			<!--p>La primera grafica representa la velocidad de conexión que se registra cada 30 minutos.</p-->

            <div class="row">
                <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 col-lg-offset-6 col-md-offset-6 templatemo-content-wrapper">
                    <div class="templatemo-content">
                        
                        <section id="home-text" class="active templatemo-content-section">
                            <div class="col-sm-12 col-md-12 col-lg-12">
                                <h3>Connection Errors</h3>
                                <p>
                                
	<div class="datagrid">

        <table border="1" width="100%">
        <thead>
            <tr>
                <th align="center"></th>
                <th align="center"></th>
                <th align="center">?</th>
                <th align="center">IP</th>
                <th align="center">INICIO</th>
                <th align="center">FIN</th>
                <th align="center">DIFF</th>
                <th align="center">COUNT</th>
            </tr>
        </thead>
        <!--tfoot>
         <tr>
            <td colspan="8">
               <div id="paging">
                  <ul>
                     <li><a href="#"><span>Previous</span></a></li>
                     <li><a href="#" class="active"><span>1</span></a></li>
                     <li><a href="#"><span>2</span></a></li>
                     <li><a href="#"><span>3</span></a></li>
                     <li><a href="#"><span>4</span></a></li>
                     <li><a href="#"><span>5</span></a></li>
                     <li><a href="#"><span>Next</span></a></li>
                  </ul>
               </div>
         </tr>
      </tfoot -->        
      <tbody>
        <?php
            $connect = mysql_connect("localhost:3306","administrador", "administrador");
            if (!$connect) {
                die(mysql_error());
            }
            mysql_select_db("administrador");
            $results = mysql_query("SELECT * FROM T_CHECK_INTERNET ORDER BY NCOD_INTERNO DESC");
            while($row = mysql_fetch_array($results)) {
            
            if ($row['NCOD_INTERNO']%2==0)
              { 
                echo "<tr class='alt'>"; 
              }
            else //Sino
              {
                echo "<tr>"; 
              }
              ?>
                    <td align="center">
                      <?php 
                        if ($row['NCOD_ESTADO']==1) { 
                           echo "<img src='images/green-circle.png' />"; 
                        } ELSE if ($row['NCOD_ESTADO']==0) { 
                           echo "<img src='images/red-circle.png' />"; 
                        } ELSE { 
                           echo "<img src='images/yellow-circle.png' />"; 
                        } ?>
                    </td>
                    <td align="center"><?php echo $row['NCOD_INTERNO']?></td>
                    <td align="center">
                      <?php 
                        /* 0 ok 1 error internet 2 cambio ip */
                        if ($row['NCOD_ESTADO']==1) { 
                          echo "ok"; 
                        } ELSE IF ($row['NCOD_ESTADO']==2) { 
                          echo "ip";
                        } ELSE { 
                          echo "Error"; 
                        } 
                      ?>
                    </td>
                    <td align="center"><?php echo $row['IPV4']?></td>
                    <td align="center"><?php echo $row['DFEC_INICIO']?></td>
                    <td align="center"><?php echo $row['DFEC_FIN']?></td>
                    <td align="center">
                      <?php 
 
                       $datetime1 = date_create($row['DFEC_INICIO']);
                       $datetime2 = date_create($row['DFEC_FIN']);
                       $interval = date_diff($datetime1, $datetime2);
                       echo $interval->format('%YA %MM %DD %HH %IM %SS');
 
                      ?>
                    </td>
                    <td align="center"><?php echo $row['COUNT']?></td>
                </tr>

            <?php

              // contamos el total de tiempo online y offline para hacer la regla de tres.
              if (($row['NCOD_ESTADO']==1) || ($row['NCOD_ESTADO']==2)) {
                $online+=$row['COUNT'];
              } ELSE {
                $offline+=$row['COUNT']; 
              } 
            }
            ?>
            <tr>
              <td colspan="8">
              <?php
                echo "ONLINE: ". round(($online*100) / ($online+$offline),2)." %";
              ?>
              </td> 
            </tr>
            <tr>
              <td colspan="8">
              <?php
                echo "OFFLINE: ". round(($offline*100) / ($online+$offline),2)." %";  
              ?>
              </td>
            </tr>
            </tbody>
            </table>
    </body>
   </div>
      
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 footer">
                    <p class="footer-text">Copyright &copy; 2014 Interactua Development - 
                    <a href="http://interactua.no-ip.info/">Home</a></p>
                </div><!-- /.footer --> 
            </div>

	</div><!-- /#main-wrapper -->
    </body>
</html>

<?php

mysql_close($connect);

?>